home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2699 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: 23 Jan 1996 06:08:22 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4e1u0m$smj@castle.nando.net>
  8. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <tcpnntpd.16.1.17.17.34.44.2781597121.346998@the-fix.sos.on.ca>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: grail1017.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <tcpnntpd.16.1.17.17.34.44.2781597121.346998@the-fix.sos.on.ca>,
  14. <verneb@the-fix.sos.on.ca> writes:
  15.  
  16. >To: INT:phsung@cs.cuhk.hk
  17. >
  18. >Int:phsung@cs.cuhk.hk,
  19. >
  20. >I >Hi, all,
  21. >I >
  22. >I >    It's said that the function main must return an integer value
  23. >I >but I just don't know what value should be returned.  Also, if I quit
  24. >I >main by exit(), what's the use of the return value?
  25. >I >
  26. >
  27. >    simply use return 0; and that will satisfy your compiler e.g.
  28. >    
  29. >    #include <stdio.h>
  30. >    int main(void)
  31. >    {
  32. >        printf("This should work I think, I hope, I know it will!\n");
  33. >    return 0;
  34. >    }
  35. >    
  36. >    Main is asking for nothing so you return the same by 'return 0;'.
  37.  
  38. That last statement may be interpreted by a beginner to mean that
  39. since main()'s arguments are "void" then you should return 0.  Of
  40. course, main() is declared to return an int, so one must return one.
  41.  
  42. Returning a 0 means the operating will receive a value indicating
  43. successful completion (it may be different from 0 and may even
  44. be something other than an integer).
  45.  
  46. To the original poster, include <stdlib.h> and return EXIT_SUCCESS or
  47. return 0 for successful completion.  Return EXIT_FAILURE if there is
  48. a failure.  The same applies to exit().
  49.  
  50. Bill McCarthy
  51. actuary@nando.net
  52. Wendell, NC  USA
  53.